#include <iostream>
using namespace std;


void test1() {
    string s1("hello world");
    s1.reserve(100);
    cout << s1.size() << endl;
    cout << s1.capacity() << endl;

    string s2(s1);
    s1.resize(100);
    cout << s1.size() << endl;
    cout << s1.capacity() << endl;

    s2.resize(5);
    cout << s2 << endl;
}

void test2(){
    string s1("hello world");
    string ::iterator pc = s1.begin();
    while (pc != s1.end()){
        cout << *pc << " ";
        ++pc;
    }
}

void test3(){
    string s1("hello world");
    string::iterator pc = s1.begin();
    while (pc != s1.end()){
        *pc += 1;
        cout << *pc << " ";
        ++pc;
    }
}

void test4(){
    string s1("hello world");
    string::reverse_iterator rpc = s1.rbegin();
    while (rpc != s1.rend()){
        cout << *rpc << " ";
        ++rpc;
    }
}

void test5(){
    string s1("hello world");
    //s1.insert(s1.begin() + 5,5,'*');
    string s2("lupenghang");
    s1.reserve(100);
    cout << s1.size() << endl;
    cout << s1.capacity() << endl;
    s1 += s2;
    cout << s1 << endl;
}

void test6(){
    string s1("hello China I love you");
    string newStr;
    size_t num = 0;
    for (auto pc:s1) {
        if(pc == ' ')
            ++num;
    }
    newStr.reserve(s1.size() + 2*num);
    for (auto pc:s1) {
        if (pc != ' ')
            newStr += pc;
        else
            newStr += "**";
    }
    cout << newStr << endl;
}

void test7(){
    string s1("string.substr.cpp");
    size_t pos = s1.rfind('.');
    string suffix = s1.substr(pos);
    cout << s1 << endl << suffix << endl;
}

void test8(){
    string s1("hello world!");
    string s2("low");
    size_t found = s1.find_first_of(s2);
    while (found != string::npos){
        s1[found] = '*';
        found = s1.find_first_of(s2,found+1);
    }
    cout << s1 << endl;
}

void test9(){
    string s1("hello world");
    cout << s1.c_str() << endl;
}

int main(){
    test9();
    return 0;
}